package cn.net.gemai.springboot_mybatis.mapper;

import cn.net.gemai.springboot_mybatis.entity.Params;
import cn.net.gemai.springboot_mybatis.entity.Person;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Repository;

import java.util.List;

//@Mapper
//可以在每个mapper接口文件单独配置@Mapper 或者在启动类中添加@MapperScan(basePackages = "cn.net.gemai.springboot_mybatis.mapper")
@Component
@Repository
public interface PersonMapper {
//  --------------------------  使用xml配置 -------------------------------
    int getPersonCount();//查询数量
    List<Person> selectAll();//查询所有
    Person selectById(int id);//通过ID查询
    List<Person> selectByParams(String name, int gender);//多参数查询
    List<Person> selectByParams2(@Param("params") Params params);//传入实体对象查询
    List<Person> selectAll2();//使用resultMap映射返回结果

    Person selectById_CallProcedure(int id);//简单调用存储过程

    int addPerson(@Param("p")Person person);//新增
    int deleteById(int id);//删除
    int update(@Param("p")Person person);//更新
//  ------------------------------------------------------------------------

//  --------------------------------------  使用注解 -------------------------
    @Select("select * from person where pid = #{id}")
    Person selectById2(int id);

    @Select("select * from person where p_name like CONCAT('%',#{name},'%') and gender=#{gender}")
    List<Person> selectByParams3(@Param("name") String name, @Param("gender") int gender);
//  ------------------------------------------------------------------------
}

